import logging
from logging import Logger, Formatter, StreamHandler

BASIC_FORMAT = f"%(asctime)s %(levelname)s %(name)s : %(message)s"


class LoggerManager:
    logger = {}

    @classmethod
    def get_logger(cls, name="default", log_level=None, log_format=BASIC_FORMAT):
        key = (name, log_level)
        def gen_logger():
            log_formatter = Formatter(log_format)
            handler = StreamHandler()
            handler.setFormatter(log_formatter)
            handler.setLevel(log_level or logging.INFO)
            _logger = Logger(name)
            _logger.setLevel(log_level or logging.INFO)
            _logger.addHandler(handler)
            cls.logger[key] = _logger
            return _logger

        return cls.logger.get(key,None) or gen_logger()

get_logger = LoggerManager.get_logger
